<!doctype html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Linux命令," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1" />






<meta name="description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;减少文件大小有两个明显的好处，一是可以减少存储空间，二是通过网络传输文件时，可以减少传输的时间。gzip是在Linux系统中经常使用的一个对文件进行压缩和解压缩的命令，既方便又好用。gzip不仅可以用来压缩大的、较少使用的文件以节省磁盘空间，还可以和tar命令一起构成Linux操作系统中比较流行的压缩文">
<meta name="keywords" content="Linux命令">
<meta property="og:type" content="article">
<meta property="og:title" content="Linux 命令- gzip">
<meta property="og:url" content="https://hcldirgit.github.io/2017/09/03/2. Linux 命令/32. Linux 命令- gzip/index.html">
<meta property="og:site_name" content="失落的乐章">
<meta property="og:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;减少文件大小有两个明显的好处，一是可以减少存储空间，二是通过网络传输文件时，可以减少传输的时间。gzip是在Linux系统中经常使用的一个对文件进行压缩和解压缩的命令，既方便又好用。gzip不仅可以用来压缩大的、较少使用的文件以节省磁盘空间，还可以和tar命令一起构成Linux操作系统中比较流行的压缩文">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2017-09-01T08:35:07.539Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Linux 命令- gzip">
<meta name="twitter:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;减少文件大小有两个明显的好处，一是可以减少存储空间，二是通过网络传输文件时，可以减少传输的时间。gzip是在Linux系统中经常使用的一个对文件进行压缩和解压缩的命令，既方便又好用。gzip不仅可以用来压缩大的、较少使用的文件以节省磁盘空间，还可以和tar命令一起构成Linux操作系统中比较流行的压缩文">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://hcldirgit.github.io/2017/09/03/2. Linux 命令/32. Linux 命令- gzip/"/>





  <title>Linux 命令- gzip | 失落的乐章</title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  




<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', '85*****1', 'auto');
  ga('send', 'pageview');
</script>


  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?87980c**************99ec5e26fb5";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>











  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">失落的乐章</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">技术面前，永远都是学生。</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-message">
          <a href="/message" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-external-link"></i> <br />
            
            留言
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://hcldirgit.github.io/2017/09/03/2. Linux 命令/32. Linux 命令- gzip/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="失落的乐章">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/0.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="失落的乐章">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Linux 命令- gzip</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-03T01:57:34+08:00">
                2017-09-03
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;减少文件大小有两个明显的好处，一是可以减少存储空间，二是通过网络传输文件时，可以减少传输的时间。gzip是在Linux系统中经常使用的一个对文件进行压缩和解压缩的命令，既方便又好用。gzip不仅可以用来压缩大的、较少使用的文件以节省磁盘空间，还可以和tar命令一起构成Linux操作系统中比较流行的压缩文件格式。据统计，gzip命令对文本文件有60%～70%的压缩率。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;gzip 不能压缩目录</p>
<h2 id="1-命令格式"><a href="#1-命令格式" class="headerlink" title="1.命令格式"></a>1.命令格式</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">gzip [参数] [文件]</div></pre></td></tr></table></figure>
<h2 id="2-命令功能"><a href="#2-命令功能" class="headerlink" title="2.命令功能"></a>2.命令功能</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;gzip 是个使用广泛的压缩程序，文件经它压缩后，其名称后面会多出 “.gz” 的扩展名。</p>
<h2 id="3-命令参数"><a href="#3-命令参数" class="headerlink" title="3.命令参数"></a>3.命令参数</h2><ul>
<li>-a或–ascii 　使用ASCII文字模式。</li>
<li>-c或–stdout或–to-stdout 　把压缩后的文件输出到标准输出设备，不去更动原始文件。 </li>
<li>-d或–decompress或—-uncompress 　解开压缩文件。</li>
<li>-f或–force 　强行压缩文件。不理会文件名称或硬连接是否存在以及该文件是否为符号连接。 </li>
<li>-h或–help 　在线帮助。 </li>
<li>-l或–list 　列出压缩文件的相关信息。</li>
<li>-L或–license 　显示版本与版权信息。 </li>
<li>-n或–no-name 　压缩文件时，不保存原来的文件名称及时间戳记。 </li>
<li>-N或–name 　压缩文件时，保存原来的文件名称及时间戳记。 </li>
<li>-q或–quiet 　不显示警告信息。</li>
<li>-r或–recursive 　递归处理，将指定目录下的所有文件及子目录一并处理。 </li>
<li>-S&lt;压缩字尾字符串&gt;或—-suffix&lt;压缩字尾字符串&gt; 　更改压缩字尾字符串。</li>
<li>-t或–test 　测试压缩文件是否正确无误。</li>
<li>-v或–verbose 　显示指令执行过程。 </li>
<li>-V或–version 　显示版本信息。</li>
<li>-num 用指定的数字num调整压缩的速度，-1或–fast表示最快压缩方法（低压缩比），-9或–best表示最慢压缩方法（高压缩比）。系统缺省值为6。</li>
</ul>
<h2 id="4-使用实例"><a href="#4-使用实例" class="headerlink" title="4.使用实例"></a>4.使用实例</h2><h3 id="实例1-把-test6-目录下的每个文件压缩成-gz-文件"><a href="#实例1-把-test6-目录下的每个文件压缩成-gz-文件" class="headerlink" title="实例1.把 test6 目录下的每个文件压缩成 .gz 文件"></a>实例1.把 test6 目录下的每个文件压缩成 .gz 文件</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">gzip *</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div></pre></td><td class="code"><pre><div class="line">[root@localhost test6]<span class="comment"># ll</span></div><div class="line">总计 604</div><div class="line">---xr--r-- 1 root mail  302108 11-30 08:39 linklog.log</div><div class="line">---xr--r-- 1 mail users 302108 11-30 08:39 log2012.log</div><div class="line">-rw-r--r-- 1 mail users     61 11-30 08:39 log2013.log</div><div class="line">-rw-r--r-- 1 root mail       0 11-30 08:39 log2014.log</div><div class="line">-rw-r--r-- 1 root mail       0 11-30 08:39 log2015.log</div><div class="line">-rw-r--r-- 1 root mail       0 11-30 08:39 log2016.log</div><div class="line">-rw-r--r-- 1 root mail       0 11-30 08:39 log2017.log</div><div class="line">[root@localhost test6]<span class="comment"># gzip *</span></div><div class="line">[root@localhost test6]<span class="comment"># ll</span></div><div class="line">总计 28</div><div class="line">---xr--r-- 1 root mail  1341 11-30 08:39 linklog.log.gz</div><div class="line">---xr--r-- 1 mail users 1341 11-30 08:39 log2012.log.gz</div><div class="line">-rw-r--r-- 1 mail users   70 11-30 08:39 log2013.log.gz</div><div class="line">-rw-r--r-- 1 root mail    32 11-30 08:39 log2014.log.gz</div><div class="line">-rw-r--r-- 1 root mail    32 11-30 08:39 log2015.log.gz</div><div class="line">-rw-r--r-- 1 root mail    32 11-30 08:39 log2016.log.gz</div><div class="line">-rw-r--r-- 1 root mail    32 11-30 08:39 log2017.log.gz</div><div class="line">[root@localhost test6]<span class="comment">#</span></div></pre></td></tr></table></figure>
<h2 id="实例2：把例1中每个压缩的文件解压，并列出详细的信息"><a href="#实例2：把例1中每个压缩的文件解压，并列出详细的信息" class="headerlink" title="实例2：把例1中每个压缩的文件解压，并列出详细的信息"></a>实例2：把例1中每个压缩的文件解压，并列出详细的信息</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">gzip -dv *</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div></pre></td><td class="code"><pre><div class="line">[root@localhost test6]<span class="comment"># ll</span></div><div class="line">总计 28</div><div class="line">---xr--r-- 1 root mail  1341 11-30 08:39 linklog.log.gz</div><div class="line">---xr--r-- 1 mail users 1341 11-30 08:39 log2012.log.gz</div><div class="line">-rw-r--r-- 1 mail users   70 11-30 08:39 log2013.log.gz</div><div class="line">-rw-r--r-- 1 root mail    32 11-30 08:39 log2014.log.gz</div><div class="line">-rw-r--r-- 1 root mail    32 11-30 08:39 log2015.log.gz</div><div class="line">-rw-r--r-- 1 root mail    32 11-30 08:39 log2016.log.gz</div><div class="line">-rw-r--r-- 1 root mail    32 11-30 08:39 log2017.log.gz</div><div class="line">[root@localhost test6]<span class="comment"># gzip -dv *</span></div><div class="line">linklog.log.gz:  99.6% -- replaced with linklog.log</div><div class="line">log2012.log.gz:  99.6% -- replaced with log2012.log</div><div class="line">log2013.log.gz:  47.5% -- replaced with log2013.log</div><div class="line">log2014.log.gz:   0.0% -- replaced with log2014.log</div><div class="line">log2015.log.gz:   0.0% -- replaced with log2015.log</div><div class="line">log2016.log.gz:   0.0% -- replaced with log2016.log</div><div class="line">log2017.log.gz:   0.0% -- replaced with log2017.log</div><div class="line">[root@localhost test6]<span class="comment"># ll</span></div><div class="line">总计 604</div><div class="line">---xr--r-- 1 root mail  302108 11-30 08:39 linklog.log</div><div class="line">---xr--r-- 1 mail users 302108 11-30 08:39 log2012.log</div><div class="line">-rw-r--r-- 1 mail users     61 11-30 08:39 log2013.log</div><div class="line">-rw-r--r-- 1 root mail       0 11-30 08:39 log2014.log</div><div class="line">-rw-r--r-- 1 root mail       0 11-30 08:39 log2015.log</div><div class="line">-rw-r--r-- 1 root mail       0 11-30 08:39 log2016.log</div><div class="line">-rw-r--r-- 1 root mail       0 11-30 08:39 log2017.log</div><div class="line">[root@localhost test6]<span class="comment">#</span></div></pre></td></tr></table></figure>
<h3 id="实例3：详细显示例1中诶每个压缩的文件的信息，并不解压"><a href="#实例3：详细显示例1中诶每个压缩的文件的信息，并不解压" class="headerlink" title="实例3：详细显示例1中诶每个压缩的文件的信息，并不解压"></a>实例3：详细显示例1中诶每个压缩的文件的信息，并不解压</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">gzip -l *</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">[root@localhost test6]<span class="comment"># gzip -l *</span></div><div class="line">         compressed        uncompressed  ratio uncompressed_name</div><div class="line">               1341              302108  99.6% linklog.log</div><div class="line">               1341              302108  99.6% log2012.log</div><div class="line">                 70                  61  47.5% log2013.log</div><div class="line">                 32                   0   0.0% log2014.log</div><div class="line">                 32                   0   0.0% log2015.log</div><div class="line">                 32                   0   0.0% log2016.log</div><div class="line">                 32                   0   0.0% log2017.log</div><div class="line">               2880              604277  99.5% (totals)</div></pre></td></tr></table></figure>
<h3 id="实例4：压缩一个-tar-备份文件，此时压缩文件的扩展名为-tar-gz"><a href="#实例4：压缩一个-tar-备份文件，此时压缩文件的扩展名为-tar-gz" class="headerlink" title="实例4：压缩一个 tar 备份文件，此时压缩文件的扩展名为 .tar.gz"></a>实例4：压缩一个 tar 备份文件，此时压缩文件的扩展名为 .tar.gz</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">gzip -r log.tar</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ls -al log.tar</span></div><div class="line">-rw-r--r-- 1 root root 307200 11-29 17:54 log.tar</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># gzip -r log.tar</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># ls -al log.tar.gz </span></div><div class="line">-rw-r--r-- 1 root root 1421 11-29 17:54 log.tar.gz</div></pre></td></tr></table></figure>
<h3 id="实例5L递归的压缩目录"><a href="#实例5L递归的压缩目录" class="headerlink" title="实例5L递归的压缩目录"></a>实例5L递归的压缩目录</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">gzip -rv test6</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div></pre></td><td class="code"><pre><div class="line">[root@localhost test6]<span class="comment"># ll</span></div><div class="line">总计 604</div><div class="line">---xr--r-- 1 root mail  302108 11-30 08:39 linklog.log</div><div class="line">---xr--r-- 1 mail users 302108 11-30 08:39 log2012.log</div><div class="line">-rw-r--r-- 1 mail users     61 11-30 08:39 log2013.log</div><div class="line">-rw-r--r-- 1 root mail       0 11-30 08:39 log2014.log</div><div class="line">-rw-r--r-- 1 root mail       0 11-30 08:39 log2015.log</div><div class="line">-rw-r--r-- 1 root mail       0 11-30 08:39 log2016.log</div><div class="line">-rw-r--r-- 1 root mail       0 11-30 08:39 log2017.log</div><div class="line">[root@localhost test6]<span class="comment"># cd ..</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># gzip -rv test6</span></div><div class="line">test6/log2014.log:        0.0% -- replaced with test6/log2014.log.gz</div><div class="line">test6/linklog.log:       99.6% -- replaced with test6/linklog.log.gz</div><div class="line">test6/log2015.log:        0.0% -- replaced with test6/log2015.log.gz</div><div class="line">test6/log2013.log:       47.5% -- replaced with test6/log2013.log.gz</div><div class="line">test6/log2012.log:       99.6% -- replaced with test6/log2012.log.gz</div><div class="line">test6/log2017.log:        0.0% -- replaced with test6/log2017.log.gz</div><div class="line">test6/log2016.log:        0.0% -- replaced with test6/log2016.log.gz</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cd test6</span></div><div class="line">[root@localhost test6]<span class="comment"># ll</span></div><div class="line">总计 28</div><div class="line">---xr--r-- 1 root mail  1341 11-30 08:39 linklog.log.gz</div><div class="line">---xr--r-- 1 mail users 1341 11-30 08:39 log2012.log.gz</div><div class="line">-rw-r--r-- 1 mail users   70 11-30 08:39 log2013.log.gz</div><div class="line">-rw-r--r-- 1 root mail    32 11-30 08:39 log2014.log.gz</div><div class="line">-rw-r--r-- 1 root mail    32 11-30 08:39 log2015.log.gz</div><div class="line">-rw-r--r-- 1 root mail    32 11-30 08:39 log2016.log.gz</div><div class="line">-rw-r--r-- 1 root mail    32 11-30 08:39 log2017.log.gz</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong><br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这样，所有 test 下面的文件都变成了 <em>.gz ，目录依然存在，只是目录里面的文件相应变成了 </em>.gz 这就是压缩，和打包不同。因为是对目录操作，所以需要加上 -r 选项，这样也可以对子目录进行递归了。</p>
<h3 id="实例6：递归地解压目录"><a href="#实例6：递归地解压目录" class="headerlink" title="实例6：递归地解压目录"></a>实例6：递归地解压目录</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">gzip -dr test6</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div></pre></td><td class="code"><pre><div class="line">[root@localhost test6]<span class="comment"># ll</span></div><div class="line">总计 28</div><div class="line">---xr--r-- 1 root mail  1341 11-30 08:39 linklog.log.gz</div><div class="line">---xr--r-- 1 mail users 1341 11-30 08:39 log2012.log.gz</div><div class="line">-rw-r--r-- 1 mail users   70 11-30 08:39 log2013.log.gz</div><div class="line">-rw-r--r-- 1 root mail    32 11-30 08:39 log2014.log.gz</div><div class="line">-rw-r--r-- 1 root mail    32 11-30 08:39 log2015.log.gz</div><div class="line">-rw-r--r-- 1 root mail    32 11-30 08:39 log2016.log.gz</div><div class="line">-rw-r--r-- 1 root mail    32 11-30 08:39 log2017.log.gz</div><div class="line">[root@localhost test6]<span class="comment"># cd ..</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># gzip -dr test6</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># cd test6</span></div><div class="line">[root@localhost test6]<span class="comment"># ll</span></div><div class="line">总计 604</div><div class="line">---xr--r-- 1 root mail  302108 11-30 08:39 linklog.log</div><div class="line">---xr--r-- 1 mail users 302108 11-30 08:39 log2012.log</div><div class="line">-rw-r--r-- 1 mail users     61 11-30 08:39 log2013.log</div><div class="line">-rw-r--r-- 1 root mail       0 11-30 08:39 log2014.log</div><div class="line">-rw-r--r-- 1 root mail       0 11-30 08:39 log2015.log</div><div class="line">-rw-r--r-- 1 root mail       0 11-30 08:39 log2016.log</div><div class="line">-rw-r--r-- 1 root mail       0 11-30 08:39 log2017.log</div><div class="line">[root@localhost test6]<span class="comment">#</span></div></pre></td></tr></table></figure>
<h3 id="实例7：-lt-数字-gt-自定义压缩率"><a href="#实例7：-lt-数字-gt-自定义压缩率" class="headerlink" title="实例7：-&lt;数字&gt; 自定义压缩率"></a>实例7：-&lt;数字&gt; 自定义压缩率</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">gzip -v -9 test.tar</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># gzip -v -1 test.tar</span></div><div class="line">test.tar: 88.4% -- replaced with test.tar.gz</div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># gzip -d test.tar.gz</span></div><div class="line">[root@localhost <span class="built_in">test</span>]<span class="comment"># gzip -v -9 test.tar</span></div><div class="line">test.tar: 89.7% -- replaced with test.tar.gz</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;压缩等级，1压缩最差，9压缩最好，6为默认。</p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Linux命令/" rel="tag"># Linux命令</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/09/03/2. Linux 命令/44. Linux 命令- kill/" rel="next" title="Linux 命令- kill">
                <i class="fa fa-chevron-left"></i> Linux 命令- kill
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/09/03/2. Linux 命令/58. Linux 命令- netstat/" rel="prev" title="Linux 命令- netstat">
                Linux 命令- netstat <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/0.png"
               alt="失落的乐章" />
          <p class="site-author-name" itemprop="name">失落的乐章</p>
           
              <p class="site-description motion-element" itemprop="description">失落的乐章的Blog</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/">
                <span class="site-state-item-count">627</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">38</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/hcldirgit" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-命令格式"><span class="nav-number">1.</span> <span class="nav-text">1.命令格式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-命令功能"><span class="nav-number">2.</span> <span class="nav-text">2.命令功能</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-命令参数"><span class="nav-number">3.</span> <span class="nav-text">3.命令参数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-使用实例"><span class="nav-number">4.</span> <span class="nav-text">4.使用实例</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#实例1-把-test6-目录下的每个文件压缩成-gz-文件"><span class="nav-number">4.1.</span> <span class="nav-text">实例1.把 test6 目录下的每个文件压缩成 .gz 文件</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#实例2：把例1中每个压缩的文件解压，并列出详细的信息"><span class="nav-number">5.</span> <span class="nav-text">实例2：把例1中每个压缩的文件解压，并列出详细的信息</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#实例3：详细显示例1中诶每个压缩的文件的信息，并不解压"><span class="nav-number">5.1.</span> <span class="nav-text">实例3：详细显示例1中诶每个压缩的文件的信息，并不解压</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例4：压缩一个-tar-备份文件，此时压缩文件的扩展名为-tar-gz"><span class="nav-number">5.2.</span> <span class="nav-text">实例4：压缩一个 tar 备份文件，此时压缩文件的扩展名为 .tar.gz</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例5L递归的压缩目录"><span class="nav-number">5.3.</span> <span class="nav-text">实例5L递归的压缩目录</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例6：递归地解压目录"><span class="nav-number">5.4.</span> <span class="nav-text">实例6：递归地解压目录</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例7：-lt-数字-gt-自定义压缩率"><span class="nav-number">5.5.</span> <span class="nav-text">实例7：-<数字> 自定义压缩率</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">失落的乐章</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  





  





  






  





  

  

  

  

  

  

</body>
</html>
